#include<bits/stdc++.h>
using namespace std;
char buf[(1<<21)+5],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
int read() {
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)) {
		f|=(ch=='-');
		ch=getchar();
	}
	while(isdigit(ch)) {
		x=x*10+ch-'0';
		ch=getchar();
	}
	return f?-x:x;
}
int n,k,Q,ans,t,ans1;
int a[1000010];
void dfs(int x,int l,int r,int s) {
	if(l == 1 && r == n) {
		ans += s;
		return;
	}
	int t = 0;
	if(x >= a[l - 1]) l--,s++,t = 1;
	if(x >= a[r + 1]) r++,s++,t = 1;
	if(t == 1) dfs(x,l,r,s);
	else {
		x = min(a[l - 1],a[r + 1]);
		dfs(x,l,r,s + k);
	}
}
signed main() {
	freopen("summer.in","r",stdin);
	freopen("summer.out","w",stdout);
	n = read(),k = read();
	for(int i = 1 ; i <= n ; i++) a[i] = read();
	a[0] = a[n + 1] = 1e9;
	Q = read();
	while(Q--) {
		int x = read(),l = read(),r = read();
		ans = 0;
		swap(a[x],a[x + 1]);
		for(int i = l ; i <= r ; i++)
			dfs(a[i],i,i,0);
		cout << ans << endl;
	}
	return 0;
}
/*
7 7
4 3 2 1 2 3 4
5
1 1 3
2 3 5
3 2 5
4 1 5
5 1 5
*/
